package lex.netant;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.URL;

public class RandomOutputStream {
	URL url;
	String file;
	long nStartPos;
	RandomAccessFile randomAccessFile;

	public RandomOutputStream(String objFile, long nStartPos) throws IOException {
		this.nStartPos = nStartPos;
		this.file = objFile;
		randomAccessFile = new RandomAccessFile(objFile, "rw");
		//
		randomAccessFile.seek(nStartPos);
	}

	public synchronized int write(byte[] b, int nStart, int len) {
		int n = -1;
		try {
			randomAccessFile.write(b, nStart, len);
			n = len;
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
		return n;
	}

	public void close() throws IOException {
		randomAccessFile.close();
	}
}
